package com.zhixue.content.controller;

import com.zhixue.content.model.dto.*;
import com.zhixue.content.service.TeachplanService;
import com.zhixue.r.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: 李 力
 * @Date: 2025/4/8
 * @Description: com.zhixue.content.controller
 * @version: 1.0
 */
@RequestMapping
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService teachplanService;

    //查询课程计划
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTeachplanInfo(@PathVariable Long courseId) {
        return teachplanService.getTeachplanInfo(courseId);
    }

    //新增/修改课程计划
    @PostMapping("/teachplan")
    public void saveOrUpdate(@RequestBody SaveTeachplanDto saveTeachplanDto) {
        teachplanService.addOrUpdate(saveTeachplanDto);
    }

    //删除课程计划
    @DeleteMapping("/teachplan/{id}")
    public R deleteById(@PathVariable("id") Long id) {
        return teachplanService.deleteById(id);
    }

    //向下移动
    @PostMapping("/movedown/{id}")
    public void moveDown(@PathVariable("id") Long id) {
        teachplanService.moveDown(id);
    }

    //向上移动
    @PostMapping("/moveup/{id}")
    public void moveUp(@PathVariable("id") Long id) {
        teachplanService.moveUp(id);
    }

    //课程绑定媒资
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto) {
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    //课程媒资解绑
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public R deletePlanMedia(@PathVariable("teachPlanId") Long teachPlanId, @PathVariable("mediaId") Long mediaId) {
        return teachplanService.deletePlanMedia(teachPlanId, mediaId);
    }
}
